<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>

    /*     function getajax() {
            let p1 = new Promise((resolve, reject) => {
                $.ajax({
                    type: "get",
                    url: "./data/1.json",
                    data: {},
                    success(res) {
                        resolve([null, res])
                    },
                    error(err) {
                        resolve([err, undefined])
                    }
                })
            })
    
            return p1
        } */



    function getajax(type,url,data) {
        let p1 = new Promise((resolve, reject) => {
            $.ajax({
                type:type,
                url: url,
                data:data,
                success(res) {
                    resolve([null, res])
                },
                error(err) {
                    resolve([err, undefined])
                }
            })
        })

        return p1
    }



    // 拿取一级城市结果
    async function getcity() {

        // let [err, res] = await getajax();
        let [err, res] = await getajax("get","./data/1.json");

        if (err) {
            alert("出错了")
            return
        }

        let id = res[0].id
        console.log(id);


        // 拿取二级城市结果
        // let [err1, res1] = await p2;
        let [err1,res1]=await getajax("get","./data/2.json",{id});
        console.log(err1, res1);

    }
    getcity()








</script>